<template>
    <div class="file-item-container">
        <div>附件：</div>
        <img class="file-icon" :src="fileType(data.materialType)" alt="">
        <div class="file-content">
            <Ellipsis :content="data.materialFullName || ''"></Ellipsis>
        </div>
        <div class="mar-l20">
            <el-button class="option-btn mar-r14" @click="viewFile">预览</el-button>
            <fileDownload v-if="isBuyPerson || isCreater" :material="data" :tooltipDisabled="true" downloadClass="option-btn"></fileDownload>
            <el-button v-else class="option-btn" @click="noPermission">下载</el-button>
        </div>
        <!-- <FileModel
            v-model:model-value="fileModelShow"
            :file-data="data"/> -->
        <ContentPreviewDialog v-model="fileModelShow" :form="fileData"/>
    </div>
</template>

<script setup>
import fileDownload from '@/components/file-download.vue';
import Ellipsis from '@/components/ellipsis.vue';
// import FileModel from './view-file-model.vue';
import ContentPreviewDialog from '@/components/content-preview-dialog.vue';
import { fileType } from '@/lib/tools.js';
import { ref } from 'vue';

const emit = defineEmits(['obtain-course']);

const props = defineProps({
    data: {
        type: Object,
        default: () => {}
    },
    isCreater: { // 是否是创建者
        type: Boolean,
        default: false
    },
    isBuyPerson: { // 是否是购买者
        type: Boolean,
        default: false
    }
});

let fileModelShow = ref(false); // 文件预览弹窗是否显示

let fileData = ref({});

// 查看文件
function viewFile () {
    if (props.isBuyPerson || props.isCreater) {
        fileData.value.title = props?.data?.materialName;
        fileData.value.materialVO = props?.data?.materialVo;
        fileModelShow.value = true;
    } else {
        emit('obtain-course');
    }
}

// 没有权限下载
function noPermission () {
    emit('obtain-course');
}

</script>

<style lang="scss" scoped>
.file-item-container {
    width: 100%;
    height: 22px;
    display: flex;
    align-items: center;
    box-sizing: border-box;
    .file-icon {
        width: 22px;
        height: 22px;
        margin-left: 4px;
        margin-right: 6px;
    }
    .file-content {
        max-width: 431px;
    }
    .mar-l20 {
        margin-left: 20px;
    }
    .mar-r14 {
        margin-right: 14px;
    }
    :deep(.option-btn) {
        font-size: 14px;
        height: 14px;
        min-height: 14px;
        padding: 0;
        color: var(--srt-main-active-text-color);
        border: none;
        background-color: transparent;
        &:hover {
            background-color: transparent;
        }
    }
}
</style>